package com.vip.web.controller;


import com.vip.dao.admin.domain.User;
import com.vip.dao.order.domain.MainMenu;
import com.vip.dao.order.domain.ShopOrder;
import com.vip.service.action.SysOperLogService;
import com.vip.service.order.MainMenuService;
import com.vip.service.order.ShopOrderService;
import com.vip.web.dto.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;


@Api(value = "订单接口")
@RestController
public class OrderController {

    @Autowired
    MainMenuService menuService;


    @Autowired
    ShopOrderService shopOrderService;

    @Autowired
    SysOperLogService operLogService;


    @ResponseBody
    @ApiOperation(value = "获取我的订单")
    @RequestMapping(value = "/order/findMyOrder/{id}",method = RequestMethod.GET)
    public Result findUserOrder(@PathVariable("id") Integer uid){
        List<ShopOrder> orders = shopOrderService.findShopOrderByUid(uid.longValue());
        if(null != orders){
            HashMap<String,Object> map = new HashMap<>();
            map.put("msg","获取订单列表成功");
            map.put("status",200);
            return Result.success(orders,map);
        }else{
            HashMap<String,Object> map = new HashMap<>();
            map.put("msg","订单为空");
            map.put("status",250);
            return Result.success(null,map);
        }

    }

    @ResponseBody
    @ApiOperation(value = "获取所有订单")
    @RequestMapping(value = "/order/findAllOrder",method = RequestMethod.GET)
    public Result findUserOrder(){
        List<ShopOrder> orders = shopOrderService.findAllShopOrder();
        if(null != orders){
            HashMap<String,Object> map = new HashMap<>();
            map.put("msg","获取订单列表成功");
            map.put("status",200);
            return Result.success(orders,map);
        }else{
            HashMap<String,Object> map = new HashMap<>();
            map.put("msg","订单为空");
            map.put("status",250);
            return Result.success(null,map);
        }

    }

    /**
     *
     * @return
     */
    @ApiOperation(value = "查找所有菜单")
    @ResponseBody
    @RequestMapping(value = "/shop/findAllMenu",method = RequestMethod.GET)
    public Result findAllMenu(){
        List<MainMenu> menuList = menuService.findAll();
        HashMap<String,Object> map = new HashMap<>();
        map.put("msg","获取菜单列表成功");
        map.put("status",200);
        return Result.success(menuList,map);
    }

    @ResponseBody
    @ApiOperation(value = "订单Id查询")
    @RequestMapping(value = "/order/findOrderById/{id}",method = RequestMethod.GET)
    public Result findOrderById(@PathVariable("id") Integer id){
         ShopOrder orders = shopOrderService.findOrderById(id.longValue());
        if(null != orders){
            HashMap<String,Object> map = new HashMap<>();
            map.put("msg","订单查询成功");
            map.put("status",200);
            return Result.success(orders,map);
        }else{
            HashMap<String,Object> map = new HashMap<>();
            map.put("msg","订单为空");
            map.put("status",250);
            return Result.success(null,map);
        }

    }

    @ResponseBody
    @ApiOperation(value = "根据订单Id删除订单")
    @RequestMapping(value = "/order/deleteById",method = RequestMethod.GET)
    public Result deleteOrder(Long id){
        shopOrderService.deleteOrder(id);
        HashMap<String,Object> map = new HashMap<>();
        map.put("msg","删除订单成功");
        map.put("status",200);
        return Result.success(null,map);
    }


}
